﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NasuTek.Shion.Extencibility;
using System.Windows.Forms;

namespace Shion.AliciaSpecializedPlugin
{
    public class Plugin : IPlugin
    {
        #region IPlugin Members

        public void Load(ExtencibilityManager e)
        {
            e.Plugins.Add("AliciaSpe", new ExtencibilityManager.PluginData("Channel Information Scripts",
                "(C) 2009 NasuTek Systems",
                "NasuTek Systems",
                "Gives you basic ban, kick, and warn scripts.",
                GetType().Assembly.GetName().Version));

            new ChannelScripts(e);
        }

        #endregion
    }

    public class ChannelScripts
    {
        static IniFile ini = new IniFile("plugins/ASP_Settings.ini");
        ExtencibilityManager em;

        //Channel Reasons
        string bots1 = String.Format("Only preapproved bots are allowed to be in {0}. Under no circumstances should auto-announce scripts be used (please make sure you have your scripts string to ignore {0}).", ini.IniReadValue("data", "channel"));
        string bots2 = String.Format("We are currently not looking for any more bots for the channel. For a list of bots and their purpose, type what is bots.", "");
        string appeal = String.Format("This ban will be removed in 3 hours. If you feel this ban is in error you may appeal it at: {0}", ini.IniReadValue("data", "appealaddress"));
        string badAttitude = String.Format("Your attitude is not conducive to the desired environment.", "");
        string noSpam = String.Format("Spamming is not tolerated here.", "");
        string badNick = String.Format("Please change your nick.", "");
        string language = String.Format("Please watch your language. We want everyone to feel welcome here", "");
        string attack = String.Format("Debate the opinion and never personally attack the person making it.", "");
        string silence = String.Format("Due to your abusive conduct, you have been silenced for 15 mins. Once this timeout is over, please follow the simple rules of the channel: If you repeat yourself, post off topic links, talk in caps, are abusive to Chris or others, or use excessive explicit language you won't be able to chat anymore.", "");

        //Network reasons
        string serverslist = String.Format("To obtain the best connection, you should generally find the closest server to you: {0}", ini.IniReadValue("data", "serverlistaddress"));
        string howtopmunreg = String.Format("You and the person you would like to PM must be registered or both of you have to do /mode nick -R", "");
        string floodingislame = String.Format("Haven't you heard? Flooding is lame as any idiot can do it!", "");
        string nohatespeech = String.Format("Hate speech isn't tolerated on {0}.", ini.IniReadValue("data", "network"));
        string nopms = String.Format("Don't PM/Query/DCC/CTCP anyone without first asking their permission in the channel.", "");
        string englishonly = String.Format("Sorry no one can understand you. Most of us only speak English.", "");
        string nocaps = String.Format("Please turn off your caps lock. That's the button above your left shift key and next to your A key.", "");

        public ChannelScripts(ExtencibilityManager e)
        {
            em = e;

            ToolStripMenuItem channelscript = new ToolStripMenuItem("Channel Help Script");

            #region Help Menu
            ToolStripMenuItem help = new ToolStripMenuItem("Help");
            ToolStripMenuItem howtopmunregistered = new ToolStripMenuItem("How to PM if Unregistered");
            howtopmunregistered.Click += new EventHandler(howtopmunregistered_Click);
            ToolStripMenuItem ServerList = new ToolStripMenuItem("Server List");
            ServerList.Click += new EventHandler(ServerList_Click);
            ToolStripMenuItem BotPolicy = new ToolStripMenuItem("Bot Policy");
            BotPolicy.Click += new EventHandler(BotPolicy_Click);
            help.DropDown.Items.Add(howtopmunregistered);
            help.DropDown.Items.Add(ServerList);
            help.DropDown.Items.Add(BotPolicy);
            #endregion

            #region Warn Menu
            ToolStripMenuItem WarnMenu = new ToolStripMenuItem("Warn");
            ToolStripMenuItem EnglishOnly = new ToolStripMenuItem("English Only");
            EnglishOnly.Click += new EventHandler(EnglishOnly_Click);
            ToolStripMenuItem NoCaps = new ToolStripMenuItem("No Caps");
            NoCaps.Click += new EventHandler(NoCaps_Click);
            ToolStripMenuItem NoSpam = new ToolStripMenuItem("No Spam");
            NoSpam.Click += new EventHandler(NoSpam_Click);
            ToolStripMenuItem NoPms = new ToolStripMenuItem("No PM's");
            NoPms.Click += new EventHandler(NoPms_Click);
            ToolStripMenuItem ChangeNick = new ToolStripMenuItem("Change Nick");
            ChangeNick.Click += new EventHandler(ChangeNick_Click);
            ToolStripMenuItem BadLanguage = new ToolStripMenuItem("Bad Language");
            BadLanguage.Click += new EventHandler(BadLanguage_Click);
            ToolStripMenuItem PersonalAttacks = new ToolStripMenuItem("Personal Attacks");
            PersonalAttacks.Click += new EventHandler(PersonalAttacks_Click);
            ToolStripMenuItem BadAttitude = new ToolStripMenuItem("Bad Attitude");
            BadAttitude.Click += new EventHandler(BadAttitude_Click);
            WarnMenu.DropDown.Items.Add(EnglishOnly);
            WarnMenu.DropDown.Items.Add(NoCaps);
            WarnMenu.DropDown.Items.Add(NoSpam);
            WarnMenu.DropDown.Items.Add(NoPms);
            WarnMenu.DropDown.Items.Add(ChangeNick);
            WarnMenu.DropDown.Items.Add(BadLanguage);
            WarnMenu.DropDown.Items.Add(PersonalAttacks);
            WarnMenu.DropDown.Items.Add(BadAttitude);
            #endregion

            #region Silence User fuctions
            ToolStripMenuItem Silence15 = new ToolStripMenuItem("Silence User - 15 Minutes");
            Silence15.Click += new EventHandler(Silence15_Click);
            ToolStripMenuItem SilenceCustom = new ToolStripMenuItem("Silence User - Custom Time");
            SilenceCustom.Click += new EventHandler(SilenceCustom_Click);
            #endregion

            #region Kick Menu
            ToolStripMenuItem KickMenu = new ToolStripMenuItem("Kick");
            ToolStripMenuItem Kick = new ToolStripMenuItem("Kick");
            ToolStripMenuItem BadAttitudeKick = new ToolStripMenuItem("Bad Attitude");
            BadAttitudeKick.Click += new EventHandler(BadAttitudeKick_Click);
            ToolStripMenuItem FloodingKick = new ToolStripMenuItem("Flooding");
            FloodingKick.Click += new EventHandler(FloodingKick_Click);
            ToolStripMenuItem HateSpeechKick = new ToolStripMenuItem("Hate Speech");
            HateSpeechKick.Click += new EventHandler(HateSpeechKick_Click);
            ToolStripMenuItem NoPmsKick = new ToolStripMenuItem("No PM's");
            NoPmsKick.Click += new EventHandler(NoPmsKick_Click);
            ToolStripMenuItem NoSpamKick = new ToolStripMenuItem("No Spam");
            NoSpamKick.Click += new EventHandler(NoSpamKick_Click);
            ToolStripMenuItem BadNickKick = new ToolStripMenuItem("Bad Nick");
            BadNickKick.Click += new EventHandler(BadNickKick_Click);
            ToolStripMenuItem BadLanguageKick = new ToolStripMenuItem("Bad Langauge");
            BadLanguageKick.Click += new EventHandler(BadLanguageKick_Click);
            ToolStripMenuItem PersonalAttacksKick = new ToolStripMenuItem("Personal Attacks");
            PersonalAttacksKick.Click += new EventHandler(PersonalAttacksKick_Click);
            ToolStripMenuItem CustomKick = new ToolStripMenuItem("Enter Custom Reason");
            CustomKick.Click += new EventHandler(CustomKick_Click);
            KickMenu.DropDown.Items.Add(Kick);
            KickMenu.DropDown.Items.Add(new ToolStripSeparator());
            KickMenu.DropDown.Items.Add(BadAttitudeKick);
            KickMenu.DropDown.Items.Add(FloodingKick);
            KickMenu.DropDown.Items.Add(HateSpeechKick);
            KickMenu.DropDown.Items.Add(NoSpamKick);
            KickMenu.DropDown.Items.Add(BadNickKick);
            KickMenu.DropDown.Items.Add(BadLanguageKick);
            KickMenu.DropDown.Items.Add(PersonalAttacksKick);
            KickMenu.DropDown.Items.Add(new ToolStripSeparator());
            KickMenu.DropDown.Items.Add(CustomKick);
            #endregion

            #region Ban Menu
            ToolStripMenuItem BanMenu = new ToolStripMenuItem("Ban");
            ToolStripMenuItem BadAttitudeBan = new ToolStripMenuItem("Bad Attitude");
            BadAttitudeBan.Click += new EventHandler(BadAttitudeBan_Click);
            ToolStripMenuItem FloodingBan = new ToolStripMenuItem("Flooding");
            FloodingBan.Click += new EventHandler(FloodingBan_Click);
            ToolStripMenuItem HateSpeechBan = new ToolStripMenuItem("Hate Speech");
            HateSpeechBan.Click += new EventHandler(HateSpeechBan_Click);
            ToolStripMenuItem NoSpamBan = new ToolStripMenuItem("No Spam");
            NoSpamBan.Click += new EventHandler(NoSpamBan_Click);
            ToolStripMenuItem BadLanguageBan = new ToolStripMenuItem("Bad Language");
            BadLanguageBan.Click += new EventHandler(BadLanguageBan_Click);
            ToolStripMenuItem PersonalAttackBan = new ToolStripMenuItem("Personal Attack");
            PersonalAttackBan.Click += new EventHandler(PersonalAttackBan_Click);
            ToolStripMenuItem CustomBan = new ToolStripMenuItem("Enter Custom Reason");
            CustomBan.Click += new EventHandler(CustomBan_Click);

            BanMenu.DropDown.Items.Add(BadAttitudeBan);
            BanMenu.DropDown.Items.Add(FloodingBan);
            BanMenu.DropDown.Items.Add(HateSpeechBan);
            BanMenu.DropDown.Items.Add(NoSpamBan);
            BanMenu.DropDown.Items.Add(BadLanguageBan);
            BanMenu.DropDown.Items.Add(PersonalAttackBan);
            BanMenu.DropDown.Items.Add(CustomBan);
            #endregion

            channelscript.DropDown.Items.Add(help);
            channelscript.DropDown.Items.Add(WarnMenu);
            channelscript.DropDown.Items.Add(new ToolStripSeparator());
            channelscript.DropDown.Items.Add(Silence15);
            channelscript.DropDown.Items.Add(SilenceCustom);
            channelscript.DropDown.Items.Add(new ToolStripSeparator());
            channelscript.DropDown.Items.Add(KickMenu);
            channelscript.DropDown.Items.Add(BanMenu);
            e.NickMenu.Items.Add(channelscript);
        }

        void CustomKick_Click(object sender, EventArgs e)
        {
            GetDialog getVarible = new GetDialog("Enter the reason for the kick:");
            if (getVarible.ShowDialog() == DialogResult.OK)
            {
                foreach (ListViewItem i in em.NickListView.SelectedItems)
                {
                    em.Clients[em.activeServer].RfcKick(em.activeChannel, i.Text, getVarible.Answer);
                }
            }
        }

        void CustomBan_Click(object sender, EventArgs e)
        {
            GetDialog getVarible = new GetDialog("Enter the reason for the ban:");
            if (getVarible.ShowDialog() == DialogResult.OK)
            {
                foreach (ListViewItem i in em.NickListView.SelectedItems)
                {
                    em.Clients[em.activeServer].Ban(em.activeChannel, em.Address(em.activeServer, i.Text, 2));
                    em.Clients[em.activeServer].SendMessage(NasuTek.Shion.Agent.SendType.Message, i.Text, "You are currently being banned for: " + getVarible.Answer + " " + appeal);
                }
            }
        }

        void PersonalAttackBan_Click(object sender, EventArgs e)
        {
            foreach (ListViewItem i in em.NickListView.SelectedItems)
            {
                em.Clients[em.activeServer].Ban(em.activeChannel, em.Address(em.activeServer, i.Text, 2));
                em.Clients[em.activeServer].SendMessage(NasuTek.Shion.Agent.SendType.Message, i.Text, "You are currently being banned for: " + attack + " " + appeal);
            }
        }

        void BadLanguageBan_Click(object sender, EventArgs e)
        {
            foreach (ListViewItem i in em.NickListView.SelectedItems)
            {
                em.Clients[em.activeServer].Ban(em.activeChannel, em.Address(em.activeServer, i.Text, 2));
                em.Clients[em.activeServer].SendMessage(NasuTek.Shion.Agent.SendType.Message, i.Text, "You are currently being banned for: " + language + " " + appeal);
            }
        }

        void NoSpamBan_Click(object sender, EventArgs e)
        {
            foreach (ListViewItem i in em.NickListView.SelectedItems)
            {
                em.Clients[em.activeServer].Ban(em.activeChannel, em.Address(em.activeServer, i.Text, 2));
                em.Clients[em.activeServer].SendMessage(NasuTek.Shion.Agent.SendType.Message, i.Text, "You are currently being banned for: " + noSpam + " " + appeal);
            }
        }

        void HateSpeechBan_Click(object sender, EventArgs e)
        {
            foreach (ListViewItem i in em.NickListView.SelectedItems)
            {
                em.Clients[em.activeServer].Ban(em.activeChannel, em.Address(em.activeServer, i.Text, 2));
                em.Clients[em.activeServer].SendMessage(NasuTek.Shion.Agent.SendType.Message, i.Text, "You are currently being banned for: " + nohatespeech + " " + appeal);
            }
        }

        void FloodingBan_Click(object sender, EventArgs e)
        {
            foreach (ListViewItem i in em.NickListView.SelectedItems)
            {
                em.Clients[em.activeServer].Ban(em.activeChannel, em.Address(em.activeServer, i.Text, 2));
                em.Clients[em.activeServer].SendMessage(NasuTek.Shion.Agent.SendType.Message, i.Text, "You are currently being banned for: " + floodingislame + " " + appeal);
            }

        }

        void BadAttitudeBan_Click(object sender, EventArgs e)
        {
            foreach (ListViewItem i in em.NickListView.SelectedItems)
            {
                em.Clients[em.activeServer].Ban(em.activeChannel, em.Address(em.activeServer, i.Text, 2));
                em.Clients[em.activeServer].SendMessage(NasuTek.Shion.Agent.SendType.Message, i.Text, "You are currently being banned for: " + badAttitude + " " + appeal);
            }
        }

        void PersonalAttacksKick_Click(object sender, EventArgs e)
        {
            foreach (ListViewItem i in em.NickListView.SelectedItems)
            {
                em.Clients[em.activeServer].RfcKick(em.activeChannel, i.Text, attack);
            }
        }

        void BadLanguageKick_Click(object sender, EventArgs e)
        {
            foreach (ListViewItem i in em.NickListView.SelectedItems)
            {
                em.Clients[em.activeServer].RfcKick(em.activeChannel, i.Text, language);
            }
        }

        void BadNickKick_Click(object sender, EventArgs e)
        {
            foreach (ListViewItem i in em.NickListView.SelectedItems)
            {
                em.Clients[em.activeServer].RfcKick(em.activeChannel, i.Text, badNick);
            }
        }

        void NoSpamKick_Click(object sender, EventArgs e)
        {
            foreach (ListViewItem i in em.NickListView.SelectedItems)
            {
                em.Clients[em.activeServer].RfcKick(em.activeChannel, i.Text, noSpam);
            }
        }

        void NoPmsKick_Click(object sender, EventArgs e)
        {
            foreach (ListViewItem i in em.NickListView.SelectedItems)
            {
                em.Clients[em.activeServer].RfcKick(em.activeChannel, i.Text, nopms);
            }
        }

        void HateSpeechKick_Click(object sender, EventArgs e)
        {
            foreach (ListViewItem i in em.NickListView.SelectedItems)
            {
                em.Clients[em.activeServer].RfcKick(em.activeChannel, i.Text, nohatespeech);
            }
        }

        void FloodingKick_Click(object sender, EventArgs e)
        {
            foreach (ListViewItem i in em.NickListView.SelectedItems)
            {
                em.Clients[em.activeServer].RfcKick(em.activeChannel, i.Text, floodingislame);
            }
        }

        void BadAttitudeKick_Click(object sender, EventArgs e)
        {
            foreach (ListViewItem i in em.NickListView.SelectedItems)
            {
                em.Clients[em.activeServer].RfcKick(em.activeChannel, i.Text, badAttitude);
            }
        }

        void SilenceCustom_Click(object sender, EventArgs e)
        {
            /*
            set %chris.silenceTime1 $$?="Enter time (in minutes) to ban for:"
            mode $chan +bb ~q: $+ $address($$1, 2) ~n: $+ $address($$1, 2)
            timer 1 3 /notice $$1 %chris.r.silence1 %chris.silenceTime1 %chris.r.silence2
            %chris.silenceTime2 = %chris.silenceTime1 * 60
            timer 1 %chris.silenceTime2 /mode $chan -bb ~q: $+ $address($$1, 2) ~n: $+ $address($$1, 2)
            */
        }

        void Silence15_Click(object sender, EventArgs e)
        {
            //TODO:
            /*
                mode $chan +bb ~q: $+ $address($$1, 2) ~n: $+ $address($$1, 2)
                set %chris.silenceTime1 15
                timer 1 3 /notice $$1 %chris.r.silence1 %chris.silenceTime1 %chris.r.silence2
                timer 1 900 /mode $chan -bb ~q: $+ $address($$1, 2) ~n: $+ $address($$1, 2)
            */
        }

        void BadAttitude_Click(object sender, EventArgs e)
        {
            em.Clients[em.activeServer].SendMessage(NasuTek.Shion.Agent.SendType.Message, em.activeChannel, em.NickListView.SelectedItems[0].Text + " " + badAttitude);
        }

        void PersonalAttacks_Click(object sender, EventArgs e)
        {
            em.Clients[em.activeServer].SendMessage(NasuTek.Shion.Agent.SendType.Message, em.activeChannel, em.NickListView.SelectedItems[0].Text + " " + attack);
        }

        void BadLanguage_Click(object sender, EventArgs e)
        {
            em.Clients[em.activeServer].SendMessage(NasuTek.Shion.Agent.SendType.Message, em.activeChannel, em.NickListView.SelectedItems[0].Text + " " + language);
        }

        void ChangeNick_Click(object sender, EventArgs e)
        {
            em.Clients[em.activeServer].SendMessage(NasuTek.Shion.Agent.SendType.Message, em.activeChannel, em.NickListView.SelectedItems[0].Text + " " + badNick);
        }

        void NoPms_Click(object sender, EventArgs e)
        {
            em.Clients[em.activeServer].SendMessage(NasuTek.Shion.Agent.SendType.Message, em.activeChannel, em.NickListView.SelectedItems[0].Text + " " + nopms);
        }

        void NoSpam_Click(object sender, EventArgs e)
        {
            em.Clients[em.activeServer].SendMessage(NasuTek.Shion.Agent.SendType.Message, em.activeChannel, em.NickListView.SelectedItems[0].Text + " " + noSpam);
        }

        void NoCaps_Click(object sender, EventArgs e)
        {
            em.Clients[em.activeServer].SendMessage(NasuTek.Shion.Agent.SendType.Message, em.activeChannel, em.NickListView.SelectedItems[0].Text + " " + nocaps);
        }

        void EnglishOnly_Click(object sender, EventArgs e)
        {
            em.Clients[em.activeServer].SendMessage(NasuTek.Shion.Agent.SendType.Message, em.activeChannel, em.NickListView.SelectedItems[0].Text + " " + englishonly);
        }

        void BotPolicy_Click(object sender, EventArgs e)
        {
            em.Clients[em.activeServer].SendMessage(NasuTek.Shion.Agent.SendType.Message, em.activeChannel, bots1);
            em.Clients[em.activeServer].SendMessage(NasuTek.Shion.Agent.SendType.Message, em.activeChannel, bots2);
        }

        void ServerList_Click(object sender, EventArgs e)
        {
            em.Clients[em.activeServer].SendMessage(NasuTek.Shion.Agent.SendType.Message, em.activeChannel, serverslist);
        }

        void howtopmunregistered_Click(object sender, EventArgs e)
        {
            em.Clients[em.activeServer].SendMessage(NasuTek.Shion.Agent.SendType.Message, em.activeChannel, howtopmunreg);
        }
    }

    public class NetworkOperatorScript
    {
    }
}